package com.itheima.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.beans.Expression;

//通知类; 告诉spring增加前后要做什么
public class Advice {

    public Object around(ProceedingJoinPoint proceedingJoinPoint) {
        try {
            long l = System.currentTimeMillis();//开始时间
            Object[] args = proceedingJoinPoint.getArgs();//获得被代理对象方法的参数
            Object proceed = proceedingJoinPoint.proceed(args); //执行被代理对象原方法
            String name = proceedingJoinPoint.getSignature().getName(); //获得执行的方法的方法名
            long l1 = System.currentTimeMillis();//结束时间
            System.out.println("执行"+name+"方法时间为 :"+(l1-l)+"毫秒");
            return proceed;
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        } finally {
        }

        return null;
    }
}
